import efinance as ef
from typing import Literal
data=None
# 划分训练集和测试集
num_train = round(len(data)*0.8)
data_train = data.iloc[:num_train, :]
data_test = data.iloc[num_train:, :]
# 训练集数据和标签
X_train = data_train[['股票名称','股票代码','日期','开盘','收盘','最高','最低','成交量','成交额', '振幅', '涨跌幅', '涨跌额', '换手率']].values
y_train = data_train['换手率']  # 标签 涨还跌 1 和 0做代表
# 测试集数据和标签
X_test = data_test[['股票名称','股票代码','日期','开盘','收盘','最高','最低','成交量','成交额', '振幅', '涨跌幅', '涨跌额', '换手率']].values
y_test = data_test['换手率']   # 标签 涨还跌 1 和 0做代表
print(X_train[:10])
print(45*'-')
print(X_test[:10])

from sklearn.svm import SVC
classifier = SVC(C=1.0, kernel='rbf')
classifier.fit(X_train, y_train)
print(classifier)
y_train_pred = classifier.predict(X_train)
y_test_pred = classifier.predict(X_test)
data_train['pred'] = y_train_pred
data_test['pred'] = y_test_pred
accuracy_train = 100 * data_train[data_train.rise==data_train.pred].shape[0] / data_train.shape[0]
accuracy_test = 100 * data_test[data_test.rise==data_test.pred].shape[0] / data_test.shape[0]
print('训练集预测准确率：%.2f%%' %accuracy_train)
print('测试集预测准确率：%.2f%%' %accuracy_test)